package API.DateDome.LocalDateTimeDome;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;

/**
 * ClassName:LocalDateTimeText003
 * Package:API.DateDome.LocalDateTimeDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/2-17:41
 * @Version:v1.0
 */
public class LocalDateDome {
    /*
     * 日历类Calender
     * LocalDate:年月日
     * LocalTime:时分秒
     * LocalDateTime：年月日 时分秒*/
    public static void main(String[] args) {

        //获取当前时间的日历对象
        LocalDate localDate1 = LocalDate.now();
        System.out.println("今天的日期：" + localDate1);
        //获取指定时间的日历对象
        LocalDate localDate2 = LocalDate.of(2023, 11, 2);
        System.out.println("指定的时间：" + localDate2);
        //get系列方法获取日历中的每一个属性值
        //获取年
        int year = localDate1.getYear();
        System.out.println("年份：" + year);
        //获取月---方法一
        Month month = localDate1.getMonth();
        System.out.println("月份：" + month.getValue());
        System.out.println("月份：" + month);
        //-----方法二-----
        int month1 = localDate1.getMonthValue();
        System.out.println("月份：" + month);

        //获取日
        DayOfWeek day = localDate1.getDayOfWeek();
        System.out.println("日：" + day);

        //获取一年的第几天
        int dayOfYear = localDate1.getDayOfYear();
        System.out.println("一年的第:" + dayOfYear + "天");

        //获取星期
        DayOfWeek dayOfWeek = localDate1.getDayOfWeek();
        System.out.println(dayOfWeek);
        System.out.println(dayOfWeek.getValue());

        //is开头的方法表示判断
        System.out.println(localDate1.isBefore(localDate2));//true
        System.out.println(localDate1.isAfter(localDate2));//false

        //with开头的方法表示修改,只能是年月日
        LocalDate withLocalDate = localDate1.withYear(2022);
        System.out.println(withLocalDate);
        System.out.println(withLocalDate == localDate1);//false

        //minus开头的方法表示减少,只能减少年月日
        LocalDate minusLocalDate = localDate1.minusMonths(1);
        System.out.println(minusLocalDate);

        //plus开头的方法表示增加
        LocalDate plusLocalDate = localDate1.plusDays(39);
        System.out.println(plusLocalDate);


        System.out.println("-----判断今天是你的生日吗-------");
        LocalDate birDate = LocalDate.of(2000,04,04);
        LocalDate nowDate = LocalDate.now();
        //月 日对象
        MonthDay birMd = MonthDay.of(birDate.getMonthValue(), birDate.getDayOfMonth());
        MonthDay nowMd = MonthDay.from(nowDate);
        System.out.println("今天是你的生日吗?"+birMd.equals(nowMd));
    }
}
